//
//  CHPresentView.m
//  CarFile
//
//  Created by 陈浩 on 2017/7/31.
//  Copyright © 2017年 陈浩. All rights reserved.
//

#import "CHPresentView.h"
@interface CHPresentView ()<UITextViewDelegate>
@property (nonatomic ,strong) UITextView *textView;
@property (nonatomic ,strong) UILabel *placeholderLabel;
@property (nonatomic ,strong) UIButton *coverBtn;
@end
@implementation CHPresentView

-(instancetype)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]) {
        self.layer.cornerRadius = 5;
        self.layer.masksToBounds = YES;
        self.backgroundColor = [UIColor whiteColor];
        [self setupUI];
    }
    return self;
}


-(void)setupUI{
    
    UITextView *textView = [[UITextView alloc] initWithFrame:CGRectMake(20, 20, self.w - 40, self.w - 100)];
    textView.delegate = self;
    textView.layer.borderWidth = 1;
    textView.layer.borderColor = [UIColor colorWithHexString:@"999999" alpha:0.3f].CGColor;
    textView.layer.cornerRadius = 3;
    textView.layer.masksToBounds = YES;
    [self addSubview:textView];
    self.textView = textView;
    
    UILabel *placeholderLabel = [[UILabel alloc] initWithFrame:CGRectMake(5, 3, textView.w - 10, 25)];
    placeholderLabel.text = @"请输入您的问题";
    placeholderLabel.font = [UIFont systemFontOfSize:13];
    placeholderLabel.backgroundColor = [UIColor clearColor];
    placeholderLabel.textColor = [UIColor colorWithHexString:@"999999" alpha:0.5f];
    [textView addSubview:placeholderLabel];
    self.placeholderLabel = placeholderLabel;
    
    UIButton *sumitBtn = [[UIButton alloc] initWithFrame:CGRectMake(20, CGRectGetMaxY(textView.frame)+10, self.w - 40, 40)];
    sumitBtn.layer.cornerRadius = 5;
    sumitBtn.layer.masksToBounds = YES;
    sumitBtn.titleLabel.font = [UIFont systemFontOfSize:14];
    [sumitBtn setBackgroundColor:[UIColor colorWithHexString:@"168bce" alpha:1.0f]];
    [sumitBtn setTitle:@"提交" forState:UIControlStateNormal];
    [sumitBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [sumitBtn addTarget:self action:@selector(sumitBtnClick) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:sumitBtn];
    
}

-(void)textViewDidChange:(UITextView *)textView{
    self.placeholderLabel.hidden = textView.text.length >0 ? YES :NO;
}



-(void)sumitBtnClick{
    
    if (self.textView.text.length == 0 ) {
        [MBProgressHUD showTipMessageInWindow:@"督办问题不能为空"];
    }else{
        if ([self.delegate respondsToSelector:@selector(didSumitToResultStr:)]) {
            [self.delegate didSumitToResultStr:self.textView.text];
        }
    }
 
    
}


@end
